package unseen.games.ui;

import unseen.games.taptap.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Color;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;


/**
 * The generic Screen Manager, it is an abstract class and base of all ViewManagers
 * used to display the different pieces of information from the Ligue1 servers
 */
public abstract class GenericScreenManager{

	protected Handler mHandler;
	protected Context mContext;
	private ColorStateList mColorStateList;

	protected Animation mPushLeftInAnimation;
	protected Animation mPushLeftOutAnimation;
	protected Animation mPushRightInAnimation;
	protected Animation mPushRightOutAnimation;
	/**
	 * Constructor
	 */
	public GenericScreenManager(Context context)
	{
		mHandler = new Handler();
		mContext = context;

		mPushLeftInAnimation 	= AnimationUtils.loadAnimation(mContext, R.anim.push_left_in);
		mPushLeftOutAnimation 	= AnimationUtils.loadAnimation(mContext, R.anim.push_left_out);
		mPushRightInAnimation 	= AnimationUtils.loadAnimation(mContext, R.anim.push_right_in);
		mPushRightOutAnimation 	= AnimationUtils.loadAnimation(mContext, R.anim.push_right_out);
		
		mColorStateList = null;
		try 
		{
			Resources res = mContext.getResources();
			XmlResourceParser xpp = res.getXml(R.color.text_button);
			mColorStateList = ColorStateList.createFromXml(res, xpp);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}

	protected void setButtonPressed(Button button) {
		button.setTag(false);
//		button.setBackgroundResource(R.drawable.button_background_pressed);
		button.setTextColor(Color.WHITE);
	}

	protected void setButtonDefault(Button button) {
		button.setTag(true);
//		button.setBackgroundResource(R.drawable.button_background);
		button.setTextColor(mColorStateList);
	}

	protected void setVisibility(final View view, final int visibility) 
	{
		mHandler.post(new Runnable() 
		{
			public void run() 
			{
				view.setVisibility(visibility);
			}
		});
	}
	
	protected void showNoContentMessage(View waitingView){
		((TextView) waitingView.findViewById(R.id.waiting_text)).setText(R.string.no_high_score_content);
		((ProgressBar) waitingView.findViewById(R.id.waiting_progress)).setVisibility(View.INVISIBLE);
	}
	
	protected void hideNoContentMessage(View waitingView){
		((TextView) waitingView.findViewById(R.id.waiting_text)).setText(R.string.waiting_score);
		((ProgressBar) waitingView.findViewById(R.id.waiting_progress)).setVisibility(View.VISIBLE);
	}
}
